<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户授权</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

<div class="layui-form layuimini-form" lay-filter="userEditFormFilter">

    <div class="layui-form-item">
        <label class="layui-form-label required">用户编号</label>
        <div class="layui-input-block">
            <input type="text" name="userId" lay-verify="required" lay-reqtext="用户编号不能为空" placeholder="请输入用户编号"
                   value=""
                   class="layui-input" disabled>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">角色编号</label>
        <div class="layui-input-block">
            <select name="roleId" class="roleId" lay-verify="" lay-filter="roleIdFilter">


            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">角色名称</label>
        <div class="layui-input-block" >
            <input type="text" name="roleName"  lay-verify="required" lay-reqtext="角色名称不能为空" placeholder="请输入角色名称"
                   value=""
                   class="layui-input" disabled>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">角色描述</label>
        <div class="layui-input-block">
            <input type="text" name="roleDesc"  lay-verify="required"  lay-reqtext="角色描述不能为空" placeholder="请输入角色描述"
                   value=""
                   class="layui-input" disabled>
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>

<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>

    var userId;
    var roleName;
    var roleDesc

    function child(userId){
        this.userId = userId;
        layui.use(['form','element'], function () {
            var form = layui.form,
                layer = layui.layer,
                element = layui.element,
                $ = layui.$;

            //初始化角色菜单
            $(".roleId").empty();
            $.get("/wfx_manager/user/queryUserList",function (res) {
                var data = res.data;
                $.each(data,function (index,item) {
                    var opt = new Option(item.roleName,item.roleId,false);
                    $(".roleId").append(opt);
                })
                //重载下拉选择框
                form.render();
            })

            form.val("userEditFormFilter", {
                "userId":userId,
                "roleName": roleName,
                "roleDesc": roleDesc
            });

            //监听角色编号下拉选择框，并初始化角色名称和角色描述
            form.on('select(roleIdFilter)', function(data){
                var roleId = data.value;
                $.get("/wfx_manager/user/queryUserList",function (res) {
                    if (res.flag){
                        var data = res.data;
                        $.each(data,function (index,item) {
                            if (roleId == item.roleId){
                                var roleName = item.roleName;
                                var roleDesc = item.roleDesc;
                                form.val("userEditFormFilter", {
                                    "roleName": roleName,
                                    "roleDesc": roleDesc
                                });
                                // $(".roleName").attr("value",item.roleName);
                                // $(".roleDesc").attr("value",item.roleDesc);
                            }
                        });
                    }
                });
            });


            // //监听一级菜单添加
            // form.on('submit(saveBtn)', function (data) {
            //
            //     var data=form.val("userEditFormFilter");
            //
            //     $.ajax({
            //         contentType : "application/json",
            //         data: JSON.stringify(data),
            //         dataType:"json",
            //         type:"post",
            //         url: "/wfx_manager/user/addUser",
            //         success: function (res) {
            //             if (res.flag){
            //                 layer.msg(res.msg,function () {
            //                     //获取iframe的唯一标识
            //                     var iframeIndex = parent.layer.getFrameIndex(window.name);
            //                     //关闭iframe窗口
            //                     parent.layer.close(iframeIndex);
            //                 })
            //             }
            //             layer.msg(res.msg);
            //         }
            //     })
            //
            //
            //     return false;
            // });



        });

    }
</script>
</body>
</html>